<?php
/***
* @version $Id: admin_modules.php 336 2007-01-23 08:12:56Z flexiondotorg $
* @copyright (c) 2006 - 2007 Flexion.Org
*            (c) 2004 - 2005 Project Minerva
*            (c) 2001 - 2006 phpBB Group
* @license   http://opensource.org/licenses/gpl-license.php GNU Public License
***/

define('IN_R3BORN', true);

if (!empty($setmodules))
{
	$module['Modules']['Module_manage'] = basename(__FILE__);
	return;
}

//
// Load default header
//
$root_path = './../';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
require('./pagestart.' . $phpEx);

//
// Mode setting
//
$mode = get_var('mode','');
$module = get_var('modname','');

if (($mode == 'enable' || $mode == 'disable') && $module != '')
{
	$state = ($mode == 'enable' ? MODULE_ENABLED : MODULE_DISABLED);
	$sql = 'UPDATE ' . MODULES_TABLE . " SET module_state = $state WHERE module_name = '$module'";
	if (!($result = $db->sql_query($sql)))
	{
		message_die(CRITICAL_ERROR, $lang['Module_update_error'], "", __LINE__, __FILE__, $sql);
	}
	if (!$db->sql_affectedrows())
	{
		message_die(GENERAL_ERROR, sprintf($lang['Module_not_found'], $module));
	}

	$mvModules[$module]['state'] = $state;
	$mode = '';
	$template->assign_var('SCRIPT', "\n<script type=\"text/javascript\" language=\"javascript\">\n//<![CDATA[\nwindow.parent.frames['nav'].location.replace('index.$phpEx?pane=left&$SID');\n//]]>\n</script>\n");
}
else if ($mode == 'default' && $module != '')
{
	//$state = MODULE_DEFAULT; // Default module
	$sql = 'UPDATE ' . MODULES_TABLE . ' SET module_state = ' . MODULE_ENABLED . ' WHERE module_state = ' . MODULE_DEFAULT;
	if (!($result = $db->sql_query($sql)))
	{
		message_die(CRITICAL_ERROR, $lang['Module_update_error'], '', __LINE__, __FILE__, $sql);
	}
	$sql = 'UPDATE ' . MODULES_TABLE . ' SET module_state = ' . MODULE_DEFAULT . " WHERE `module_name` = '$module'";

	if (!($result = $db->sql_query($sql)))
	{
		message_die(CRITICAL_ERROR, $lang['Module_update_error'], '', __LINE__, __FILE__, $sql);
	}
	if (!$db->sql_affectedrows())
	{
		message_die(GENERAL_ERROR, sprintf($lang['Module_not_found'], $module));
	}

	foreach ($mvModules as $name => $value)
	{
		if ($mvModules[$name]['state'] == MODULE_DEFAULT)
		{
			$mvModules[$name]['state'] = MODULE_ENABLED;
		}
	}
	$mvModules[$module]['state'] = MODULE_DEFAULT;
	$mode = '';
}
else if ($mode == 'uninstall' && $module != '')
{
	$sql = 'DELETE FROM ' . MODULES_TABLE . " WHERE module_name = '$module'";
	if (!($result = $db->sql_query($sql)))
	{
		message_die(CRITICAL_ERROR, $lang['Module_delete_error'], '', __LINE__, __FILE__, $sql);
	}
	if (!$db->sql_affectedrows())
	{
		message_die(GENERAL_ERROR, sprintf($lang['Module_not_found'], $module));
	}

    //Delete the layouts and blocks associated with this module
    //Note! This will not delete addon blocks but just blocks parameters assigned to layouts
    //used by the add-on module

	$module_id = getModuleID($module);

	//Get all the layout ids
	$sql = 'SELECT layout_id FROM ' . LAYOUT_TABLE . " WHERE module_id = $module_id";
	if ( !($result = $db->sql_query($sql)) )
	{
    	message_die(CRITICAL_ERROR, 'Could not select page data', '', __LINE__, __FILE__, $sql);
	}

	//Recursuvely delete the block parameters assigned to these layouts.
	while( $row = $db->sql_fetchrow($result) )
	{
		$sql_block = 'DELETE FROM ' . BLOCKS_TABLE . ' WHERE layout_id = ' . $row['layout_id'];

        if (!$result_block = $db->sql_query($sql_block))
        {
        	message_die(CRITICAL_ERROR, "Could not remove data from blocks table", $lang['Error'], __LINE__, __FILE__, $sql);
        }
	}
	$db->sql_freeresult($result);

	//Now delete the layouts themselves.
	$sql = 'DELETE FROM ' . LAYOUT_TABLE . " WHERE module_id = '$module_id'";

    if (!$result = $db->sql_query($sql))
    {
    	message_die(CRITICAL_ERROR, "Could not remove data from layout table", $lang['Error'], __LINE__, __FILE__, $sql);
	}

	$mvModule_root_path = $root_path . 'modules/' . $module . '/';
	$mod_uninstall_file = "{$mvModule_root_path}install/mvUninstall.$phpEx";
	$message = '';
	if (@file_exists($mod_uninstall_file))
	{
		$message .= '<iframe width="100%" height="300" src="' . append_sid($mod_uninstall_file) . '"></iframe><br /><br />';
	}
	$message .= "\n<script type=\"text/javascript\" language=\"javascript\">\n//<![CDATA[\nwindow.parent.frames['nav'].location.replace('index.$phpEx?pane=left&$SID');\n//]]>\n</script>\n";
	$message .= sprintf($lang['Module_was_uninstalled'], $module) . '<br /><br />' . sprintf($lang['Module_click_return_admin'], '<a href="' . append_sid("admin_modules.$phpEx") . '">', '</a>') . '<br /><br />' . sprintf($lang['Click_return_admin_index'], '<a href="' . append_sid("index.$phpEx?pane=right") . '">', '</a>');
	message_die(GENERAL_MESSAGE, $message);
}
else if ($mode == 'cleanup' && $module != '')
{
	$sql = 'DELETE FROM ' . MODULES_TABLE . " WHERE `module_name` = '$module'";
	if (!($result = $db->sql_query($sql)))
	{
		message_die(CRITICAL_ERROR, $lang['Module_delete_error'], '', __LINE__, __FILE__, $sql);
	}
	if (!$db->sql_affectedrows())
	{
		message_die(GENERAL_ERROR, sprintf($lang['Module_not_found'], $module));
	}

	$module_id = getModuleID($module);
	$sql = 'DELETE FROM ' . LAYOUT_TABLE . " WHERE module_id = '$module_id'";

    if (!$result = $db->sql_query($sql))
    {
    	message_die(GENERAL_ERROR, "Could not remove data from layout table", $lang['Error'], __LINE__, __FILE__, $sql);
	}

	$message .= sprintf($lang['Module_cleaned'], $module) . '<br /><br />' . sprintf($lang['Module_click_return_admin'], '<a href="' . append_sid("admin_modules.$phpEx") . '">', '</a>') . '<br /><br />' . sprintf($lang['Click_return_admin_index'], '<a href="' . append_sid("index.$phpEx?pane=right") . '">', '</a>');
	message_die(GENERAL_MESSAGE, $message);
}
else if ($mode == 'install' && $module != '')
{
	if (array_key_exists($module, $mvModules))
	{
		$message .= sprintf($lang['Module_already_installed'], $module) . '<br /><br />' . sprintf($lang['Module_click_return_admin'], '<a href="' . append_sid("admin_modules.$phpEx") . '">', '</a>') . '<br /><br />' . sprintf($lang['Click_return_admin_index'], '<a href="' . append_sid("index.$phpEx?pane=right") . '">', '</a>');
		message_die(GENERAL_MESSAGE, $message);
	}

	$mvModule_root_path = $root_path . 'modules/' . $module . '/';
	$mod_version_file = $mvModule_root_path . "mvVersion.$phpEx";
	$mod_constants_file = $mvModule_root_path . "mvConstants.$phpEx";
	$mod_headers_file = $mvModule_root_path . "mvHeaders.$phpEx";
	$mvVersion = array();
	if (@file_exists($mod_version_file) && (@file_exists($mvModule_root_path . "$module.$phpEx") || @file_exists($mvModule_root_path . "index.$phpEx")))
	{
		include($mod_version_file);
	}
	if (count($mvVersion) < 6) // Incomplete version information
	{
		$message .= sprintf($lang['Module_incompatible'], $module) . '<br /><br />' . sprintf($lang['Module_click_return_admin'], '<a href="' . append_sid("admin_modules.$phpEx") . '">', '</a>') . '<br /><br />' . sprintf($lang['Click_return_admin_index'], '<a href="' . append_sid("index.$phpEx?pane=right") . '">', '</a>');
		message_die(GENERAL_MESSAGE, $message);
	}

	$mvModuleFilesList = '';
	$mvModuleTemplatesList = '';
	$mvModuleAdminTemplatesList = '';
	$mvModuleAdminList = '';
	$mvModuleLanguageList = '';
	$mvModuleComponentsList = '';

	$default_lang = r3born_ltrim(basename(r3born_rtrim($config['default_lang'])), "'");
	if ( (!file_exists(@realpath($root_path . 'modules/' . $module . '/language/lang_' . $default_lang . '/' . 'lang_main.' . $phpEX))) || (!file_exists(@realpath($root_path . 'modules/' . $module . '/language/lang_' . $default_lang . '/' . 'lang_admin.' . $phpEX))))
	{
		$default_lang = r3born_ltrim(basename(r3born_rtrim($userdata['user_lang'])), "'");
		if ( (!file_exists(@realpath($root_path . 'modules/' . $module . '/language/lang_' . $default_lang . '/' . 'lang_main.' . $phpEX))) || (!file_exists(@realpath($root_path . 'modules/' . $module . '/language/lang_' . $default_lang . '/' . 'lang_admin.' . $phpEX))))
		{
				$default_lang = 'english';
		}
	}

	// Let's build a file list
	$whereToLook = array(	"mvModuleFilesList#$phpEx#false" => '.',
							"mvModuleTemplatesList#tpl#true" => 'templates/' . $theme['template_name'],
							"mvModuleAdminTemplatesList#tpl#false" => 'templates/admin',
							"mvModuleAdminList#$phpEx#false" => 'admin',
							"mvModuleLanguageList#$phpEx#false" => 'language/lang_' . $default_lang,
							"mvModuleComponentsList#$phpEx#false" => 'components'
						);
	foreach ($whereToLook as $what => $dir)
	{
		list($var, $filter, $recurse, $prefix) = explode('#', $what);
		$recurse = ($recurse == "true") ? true:false;
		$$var = populate_file_tree($mvModule_root_path . $dir, $filter, $recurse, $prefix);
	}
	$mvModuleTemplatesList .= ($mvModuleTemplatesList ? ', ':'') . $mvModuleAdminTemplatesList;
	$state = MODULE_ENABLED;
	if (getModuleStatus($module) == MODULE_DEFAULT)
	{
		$state = MODULE_DEFAULT;
	}
	$sql = "INSERT INTO " . MODULES_TABLE . " ( `module_id` , `module_name` , `module_type` , `module_displayname` , `module_description` , `module_version` , `module_version_check` , `module_copyright` , `module_files` , `module_templates` , `module_admin` , `module_language` , `module_components`, `module_constants` , `module_headers` , `module_state` ) VALUES ('', '$module', $mvVersion[type], '" . str_replace("\'", "''", $mvVersion[displayname]) . "', '" . str_replace("\'", "''", $mvVersion[description]) . "', '$mvVersion[version]', '$mvVersion[version_check]', '" . str_replace("\'", "''", $mvVersion[copyright]) . "'";
	$sql .= ', ' . ($mvModuleFilesList ? "'$mvModuleFilesList'" : 'NULL');
	$sql .= ', ' . ($mvModuleTemplatesList ? "'$mvModuleTemplatesList'": 'NULL');
	$sql .= ', ' . ($mvModuleAdminList ? "'$mvModuleAdminList'" : 'NULL');
	$sql .= ', ' . ($mvModuleLanguageList ? "'$mvModuleLanguageList'" : 'NULL');
	$sql .= ', ' . ($mvModuleComponentsList ? "'$mvModuleComponentsList'" : 'NULL');
	$sql .= ', ' . (@file_exists($mod_constants_file) ? "'mvConstants.$phpEx'": 'NULL');
	$sql .= ', ' . (@file_exists($mod_headers_file) ? "'mvHeaders.$phpEx'": 'NULL');
	$sql .= ', '.$state.')';
	if (!($result = $db->sql_query($sql)))
	{
		message_die(CRITICAL_ERROR, $lang['Module_add_error'], '', __LINE__, __FILE__, $sql);
	}

	$mod_install_file = "{$mvModule_root_path}install/mvInstall.$phpEx";
	$message = '';
	if (@file_exists($mod_install_file))
	{
		$message .= '<iframe width="100%" height="300" src="' . append_sid($mod_install_file) . '"></iframe><br /><br />';
	}
	$message .= "\n<script type=\"text/javascript\" language=\"javascript\">\n//<![CDATA[\nwindow.parent.frames['nav'].location.replace('index.$phpEx?pane=left&$SID');\n//]]>\n</script>\n";
	$message .= sprintf($lang['Module_installed'], $module) . '<br /><br />' . sprintf($lang['Module_click_return_admin'], '<a href="' . append_sid("admin_modules.$phpEx") . '">', '</a>') . '<br /><br />' . sprintf($lang['Click_return_admin_index'], '<a href="' . append_sid("index.$phpEx?pane=right") . '">', '</a>');
	message_die(GENERAL_MESSAGE, $message);
}
else if ( ($mode == 'update' || $mode == 'refresh') && $module != '')
{
	if (!array_key_exists($module, $mvModules))
	{
		$message .= sprintf($lang['Module_not_found'], $module) . '<br /><br />' . sprintf($lang['Module_click_return_admin'], '<a href="' . append_sid("admin_modules.$phpEx") . '">', '</a>') . '<br /><br />' . sprintf($lang['Click_return_admin_index'], '<a href="' . append_sid("index.$phpEx?pane=right") . '">', '</a>');
		message_die(GENERAL_MESSAGE, $message);
	}

	$mvModule_root_path = $root_path . 'modules/' . $module . '/';
	$mod_version_file = $mvModule_root_path . "mvVersion.$phpEx";
	$mod_constants_file = $mvModule_root_path . "mvConstants.$phpEx";
	$mod_headers_file = $mvModule_root_path . "mvHeaders.$phpEx";
	$mvVersion = array();
	if (@file_exists($mod_version_file) && (@file_exists($mvModule_root_path . "$module.$phpEx") || @file_exists($mvModule_root_path . "index.$phpEx")))
	{
		include($mod_version_file);
	}
	if (count($mvVersion) < 6) // Incomplete version information
	{
		$message .= sprintf($lang['Module_incompatible'], $module) . '<br /><br />' . sprintf($lang['Module_click_return_admin'], '<a href="' . append_sid("admin_modules.$phpEx") . '">', '</a>') . '<br /><br />' . sprintf($lang['Click_return_admin_index'], '<a href="' . append_sid("index.$phpEx?pane=right") . '">', '</a>');
		message_die(GENERAL_MESSAGE, $message);
	}

	$mvModuleFilesList = '';
	$mvModuleTemplatesList = '';
	$mvModuleAdminTemplatesList = '';
	$mvModuleAdminList = '';
	$mvModuleLanguageList = '';
	$mvModuleComponentsList = '';

	$default_lang = r3born_ltrim(basename(r3born_rtrim($config['default_lang'])), "'");
	if ( (!file_exists(@realpath($root_path . 'modules/' . $module . '/language/lang_' . $default_lang . '/' . 'lang_main.' . $phpEX))) || (!file_exists(@realpath($root_path . 'modules/' . $module . '/language/lang_' . $default_lang . '/' . 'lang_admin.' . $phpEX))))
	{
		$default_lang = r3born_ltrim(basename(r3born_rtrim($userdata['user_lang'])), "'");
		if ( (!file_exists(@realpath($root_path . 'modules/' . $module . '/language/lang_' . $default_lang . '/' . 'lang_main.' . $phpEX))) || (!file_exists(@realpath($root_path . 'modules/' . $module . '/language/lang_' . $default_lang . '/' . 'lang_admin.' . $phpEX))))
		{
				$default_lang = 'english';
		}
	}

	// Let's build a file list
	$whereToLook = array(   "mvModuleFilesList#$phpEx#false" => '.',
							"mvModuleTemplatesList#tpl#true" => 'templates/' . $theme['template_name'],
							"mvModuleAdminTemplatesList#tpl#false" => 'templates/admin',
							"mvModuleAdminList#$phpEx#false" => 'admin',
							"mvModuleLanguageList#$phpEx#false" => 'language/lang_' . $default_lang,
							"mvModuleComponentsList#$phpEx#false" => 'components'
						);
	foreach ($whereToLook as $what => $dir)
	{
		list($var, $filter, $recurse, $prefix) = explode('#', $what);
		$recurse = ($recurse == "true") ? true:false;
		$$var = populate_file_tree($mvModule_root_path . $dir, $filter, $recurse, $prefix);
	}
	$mvModuleTemplatesList .= ($mvModuleTemplatesList ? ', ':'') . $mvModuleAdminTemplatesList;

	$sql = "UPDATE " . MODULES_TABLE . " SET `module_name` = '$module', `module_type` = $mvVersion[type], `module_displayname` = '" . str_replace("\'", "''", $mvVersion[displayname]) . "', `module_description` = '" . str_replace("\'", "''", $mvVersion[description]) . "', `module_version` = '$mvVersion[version]', `module_version_check` = '$mvVersion[version_check]', `module_copyright` = '" . str_replace("\'", "''", $mvVersion[copyright]) . "'";
	$sql .= ', `module_files` = ' . ($mvModuleFilesList ? "'$mvModuleFilesList'" : 'NULL');
	$sql .= ', `module_templates` = ' . ($mvModuleTemplatesList ? "'$mvModuleTemplatesList'" : 'NULL');
	$sql .= ', `module_admin` = ' . ($mvModuleAdminList ? "'$mvModuleAdminList'" : 'NULL');
	$sql .= ', `module_language` = ' . ($mvModuleLanguageList ? "'$mvModuleLanguageList'" : 'NULL');
	$sql .= ', `module_components` = ' . ($mvModuleComponentsList ? "'$mvModuleComponentsList'" : 'NULL');
	$sql .= ', `module_constants` = ' . (@file_exists($mod_constants_file) ? "'mvConstants.$phpEx'": 'NULL');
	$sql .= ', `module_headers` = ' . (@file_exists($mod_headers_file) ? "'mvHeaders.$phpEx'" : 'NULL');

	// If we are refreshing a module keep it state, but if updating change the state to enabled.
	if ($mode == 'refresh')
	{
		$sql .= " WHERE `module_name` = '$module'";
	}
	else
	{
		$state = MODULE_ENABLED;
		$sql .= ", `module_state` = '$state' WHERE `module_name` = '$module'";
	}

	if (!($result = $db->sql_query($sql)))
	{
		message_die(CRITICAL_ERROR, $lang['Module_update_error'], '', __LINE__, __FILE__, $sql);
	}

	// Run the update file if we are updating the module
	if ($mode == 'update')
	{
		$mod_update_file = "{$mvModule_root_path}install/mvUpdate.$phpEx";
		$message = '';
		if (@file_exists($mod_update_file))
		{
			$message .= '<iframe width="100%" height="300" src="' . append_sid($mod_update_file) . '"></iframe><br /><br />';
		}
		$message .= "\n<script type=\"text/javascript\" language=\"javascript\">\n//<![CDATA[\nwindow.parent.frames['nav'].location.replace('index.$phpEx?pane=left&$SID');\n//]]>\n</script>\n";
		$message .= sprintf($lang['Module_updated'], $module) . '<br /><br />' . sprintf($lang['Module_click_return_admin'], '<a href="' . append_sid("admin_modules.$phpEx") . '">', '</a>') . '<br /><br />' . sprintf($lang['Click_return_admin_index'], '<a href="' . append_sid("index.$phpEx?pane=right") . '">', '</a>');
		message_die(GENERAL_MESSAGE, $message);
	}
	// otherwise, pump out the successful completion of the file refresh.
	else
	{
		$message .= sprintf($lang['Module_refreshed'], $module) . '<br /><br />' . sprintf($lang['Module_click_return_admin'], '<a href="' . append_sid("admin_modules.$phpEx") . '">', '</a>') . '<br /><br />' . sprintf($lang['Click_return_admin_index'], '<a href="' . append_sid("index.$phpEx?pane=right") . '">', '</a>');
		message_die(GENERAL_MESSAGE, $message);
	}
}
else if ( $mode == 'manual' && $module != '')
{
		$message .= sprintf($lang['Module_fix_manually'], getModuleDisplayName($module)) . sprintf($lang['Module_click_return_admin'], '<a href="' . append_sid("admin_modules.$phpEx") . '">', '</a>') . '<br /><br />' . sprintf($lang['Click_return_admin_index'], '<a href="' . append_sid("index.$phpEx?pane=right") . '">', '</a>');
		message_die(GENERAL_MESSAGE, $message);
}

if ($mode == '')
{
	//
	// get list of loaded modules
	//
	$modules_path = $root_path . 'modules/';
	$mvModulesList = $mvModules;

	foreach ($mvModulesList as $name => $value)
	{
		$mvModulesList[$name]['state'] = MODULE_REMOVED;
	}
	if ($base = opendir($modules_path))
	{
		while (($dir = readdir($base)) !== false)
		{
			$mod_version_file = $modules_path . $dir . '/mvVersion.' . $phpEx;
			if ($dir[0] != "." && @file_exists($mod_version_file))
			{
				$mvVersion = array();
				include($mod_version_file);

				if (count($mvVersion) < 6) // Incomplete version information
				{
					continue;
				}

				if (array_key_exists($dir, $mvModules))
				{
					$vCompare = compare_versions($mvModules[$dir]['version'], $mvVersion['version']);

					if ($vCompare == 0) // Equal
					{
						$mvModulesList[$dir]['state'] = $mvModules[$dir]['state'];
					}
					else if ($vCompare < 0)
					{
						$mvModulesList[$dir] = $mvVersion;
						$mvModulesList[$dir]['state'] = MODULE_UPDATE_REQUIRED;
					}
					else if ($vCompare > 0) // older
					{
						$mvModulesList[$dir] = $mvVersion;
						$mvModulesList[$dir]['state'] = MODULE_ERROR; // error
					}
				}
				else
				{
					$mvModulesList[$dir] = $mvVersion;
					$mvModulesList[$dir]['state'] = MODULE_NOT_INSTALLED;
				}
			}
		}
		closedir($base);
	}
	ksort($mvModulesList);
	reset($mvModulesList);
	$i = 0;
	foreach ($mvModulesList as $name => $value)
	{
		$command1 = '';
		$command1_text = '';
		$command2 = '';
		$command2_text = '';
		$command3 = '';
		$command3_text = '';
		$command4 = '';
		$command4_text = '';
		$bold_in = '';
		$bold_out = '';
		switch($value['state'])
		{
			case MODULE_NOT_INSTALLED:
				$state = $lang['Module_short_not_installed'];
				$command1 = 'install';
				$command1_text = $lang['Module_short_install'];
				$value['description'] = stripslashes($value['description']);
				break;
			case MODULE_ENABLED:
				$state = $lang['Module_short_active'];
				$command1 = 'disable';
				$command1_text = $lang['Module_short_disable'];
				$command2 = 'uninstall';
				$command2_text = $lang['Module_short_uninstall'];
				if ($value['type'] == ADDON_MODULE)
				{
					$command3 = 'default';
					$command3_text = $lang['Module_short_make_default'];
					$command4 = 'refresh';
					$command4_text = $lang['Module_short_refresh'];
				}
				else
				{
					$command3 = 'refresh';
					$command3_text = $lang['Module_short_refresh'];
				}
				$bold_in = '<b>';
				$bold_out = '</b>';
				break;
			case MODULE_DISABLED:
				$state = $lang['Module_short_disabled'];
				$command1 = 'enable';
				$command1_text = $lang['Module_short_enable'];
				$command2 = 'uninstall';
				$command2_text = $lang['Module_short_uninstall'];
				$command3 = 'refresh';
				$command3_text = $lang['Module_short_refresh'];
				break;
			case MODULE_UPDATE_REQUIRED:
				$state = sprintf($lang['Module_short_needs_updating'], $mvModules[$name]['version']);
				$command1 = 'update';
				$command1_text = $lang['Module_short_update'];
				$bold_in = '<b class="not_ok">';
				$bold_out = '</b>';
				break;
			case MODULE_REMOVED:
				$state = $lang['Module_short_incorrect_removal'];
				$command1 = 'cleanup';
				$command1_text = $lang['Module_short_cleanup'];
				$bold_in = '<b class="not_ok">';
				$bold_out = '</b>';
				break;
			case MODULE_DEFAULT:
				$state = $lang['Module_short_default'];
				$command1 = 'disable';
				$command1_text = $lang['Module_short_disable'];
				$command2 = 'uninstall';
				$command2_text = $lang['Module_short_uninstall'];
				$command3 = 'refresh';
				$command3_text = $lang['Module_short_refresh'];
				$bold_in = '<b class="ok">';
				$bold_out = '</b>';
				break;
			case MODULE_ERROR:
				$state = sprintf($lang['Module_short_was_newer'], $mvModules[$name]['version']);
				$command1 = 'manual';
				$command1_text = $lang['Module_short_fix_manually'];
				$command2 = 'refresh';
				$command2_text = $lang['Module_short_refresh'];
				$bold_in = '<b class="not_ok">';
				$bold_out = '</b>';
				break;
		}

		if ($value['type'] == ADDON_MODULE)
		{
			$template->assign_block_vars('modules', array(
				'ID'                => $bold_in . $name . $bold_out,
				'VERSION'           => $value['version'],
				'L_NAME'            => $bold_in . $value['displayname'] . $bold_out,
				'U_NAME'            => append_sid($root_path."index.$phpEx?module=$name"),
				'DESCRIPTION'       => $value['description'],
				'COPYRIGHT'         => $value['copyright'],
				'STATE'             => $bold_in . $state . $bold_out,
				'L_COMMAND1'        => $command1_text,
				'U_COMMAND1'        => $command1 ? append_sid("admin_modules.$phpEx?mode=$command1&amp;modname=$name") : '#',
				'L_COMMAND2'        => $command2_text,
				'U_COMMAND2'        => $command2 ? append_sid("admin_modules.$phpEx?mode=$command2&amp;modname=$name") : '#',
				'L_COMMAND3'        => $command3_text,
				'U_COMMAND3'        => $command3 ? append_sid("admin_modules.$phpEx?mode=$command3&amp;modname=$name") : '#',
				'L_COMMAND4'        => $command4_text,
				'U_COMMAND4'        => $command4 ? append_sid("admin_modules.$phpEx?mode=$command4&amp;modname=$name") : '#',
				)
			);
		}
		elseif ($value['type'] == ADDON_BLOCK)
		{
			$template->assign_block_vars('blocks', array(
				'ID'                => $bold_in . $name . $bold_out,
				'VERSION'           => $value['version'],
				'L_NAME'            => $bold_in . $value['displayname'] . $bold_out,
				'DESCRIPTION'       => $value['description'],
				'COPYRIGHT'         => $value['copyright'],
				'STATE'             => $bold_in . $state . $bold_out,
				'L_COMMAND1'        => $command1_text,
				'U_COMMAND1'        => $command1 ? append_sid("admin_modules.$phpEx?mode=$command1&amp;modname=$name") : '#',
				'L_COMMAND2'        => $command2_text,
				'U_COMMAND2'        => $command2 ? append_sid("admin_modules.$phpEx?mode=$command2&amp;modname=$name") : '#',
				'L_COMMAND3'        => $command3_text,
				'U_COMMAND3'        => $command3 ? append_sid("admin_modules.$phpEx?mode=$command3&amp;modname=$name") : '#',
				'L_COMMAND4'        => $command4_text,
				'U_COMMAND4'        => $command4 ? append_sid("admin_modules.$phpEx?mode=$command4&amp;modname=$name") : '#',
				)
			);
		}
	}
}

$template->assign_vars(array(
	'L_MODULES_TITLE'   => $lang['Module_administration'],
	'L_MODULES_EXPLAIN' => $lang['Module_administration_explain'],
	'L_MODULE_ID'       => $lang['Module_id'],
	'L_MODULE_NAME'     => $lang['Module_module'],
	'L_MODULE_STATE'    => $lang['Module_status'],
	'L_MODULE_COMMAND'  => $lang['Module_action'],
	'L_BLOCKS_TITLE'    => $lang['Block_administration'],
	'L_BLOCKS_EXPLAIN'  => $lang['Block_administration_explain'],
	'L_BLOCK_ID'        => $lang['Block_id'],
	'L_BLOCK_NAME'      => $lang['Block_block'],
	'L_BLOCK_STATE'     => $lang['Block_status'],
	'L_BLOCK_COMMAND'   => $lang['Block_action'],
	)
);

$template->set_filenames(array('body' => 'modules_body.tpl'));
$template->pparse('body');
page_footer_admin();

?>